package com.cskaoyan.service;

import com.cskaoyan.bean.MarketCategory;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.AdminCategoryL1VO;
import com.cskaoyan.bean.vo.AdminCategoryVO;
import com.cskaoyan.bean.vo.AdminCategoryVO2;
import com.cskaoyan.mapper.MarketCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * \* User: 余雨健
 * \* Date: 2022/10/12
 * \* Time: 15:29
 **/
@Service
public class AdminCategoryServiceImpl implements AdminCategoryService{
    @Autowired
    MarketCategoryMapper categoryMapper;

    /**
     * 商城管理的商品类名显示
     * @return
     */
    @Override
    public CommonData<AdminCategoryVO> selectCategoryList() {
        List<AdminCategoryVO> list = new ArrayList<>();
        List<AdminCategoryVO2> adminCategoryVO2s = categoryMapper.selectPicByprimaryKey(0);
        int size = adminCategoryVO2s.size();
        for (AdminCategoryVO2 adminCategoryVO2 : adminCategoryVO2s) {
            List<AdminCategoryVO2> list1 = categoryMapper.selectPicByprimaryKey(adminCategoryVO2.getId());
            AdminCategoryVO adminCategoryVO = new AdminCategoryVO(adminCategoryVO2.getId(),adminCategoryVO2.getName(),adminCategoryVO2.getKeywords(),adminCategoryVO2.getDesc(),adminCategoryVO2.getIconUrl(),adminCategoryVO2.getPicUrl(),adminCategoryVO2.getLevel(),list1);
            list.add(adminCategoryVO);
        }
        return new CommonData<AdminCategoryVO>(size, 1, size, 1, list);
    }

    @Override
    public int insertCategory(MarketCategory marketCategory) {
        int i = categoryMapper.insertSelective(marketCategory);
        return i;
    }

    @Override
    public void deleteCategory(Integer id) {
        int i = categoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateCategory(MarketCategory marketCategory) {
        categoryMapper.updateByPrimaryKeySelective(marketCategory);
    }

    @Override
    public CommonData<AdminCategoryL1VO> selectL1Category(Integer pid) {
        List<AdminCategoryL1VO> adminCategoryL1VOS = categoryMapper.selectL1ByPrimaryKey(pid);
        int size = adminCategoryL1VOS.size();
        return new CommonData<AdminCategoryL1VO>(size,1,size,1,adminCategoryL1VOS);
    }
}
